﻿
-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Ivy_Sys_RoleMaster_Insert')
	BEGIN
		DROP  Procedure  Ivy_Sys_RoleMaster_Insert
	END

GO

CREATE PROCEDURE [Ivy_Sys_RoleMaster_Insert] 
-- =============================================
-- Author:		<Mrinmoy Das>
-- Create date: <06/09/2014>
-- Description:	<Ivy_Sys_RoleMaster_Insert>
-- =============================================
-- Add the parameters for the stored procedure here
	(
				
				@RoleCode varchar(20),
				@RoleName varchar(50),
				@RoleDescription varchar(1000) = NULL,

				@Sys_CreatedByID varchar(50)= NULL,
				@Sys_ModifiedByID varchar(50) = NULL,
				@Sys_DeleteType int = 0,
				@Sys_OrganizationID int = NULL,
				@Sys_InitialPrimaryKeys varchar(max)= NULL,
				@Sys_WorkstationName varchar(50)= NULL,
				
				@Sys_DateOfCreation datetime OUTPUT,
				@RoleKey int OUTPUT
	)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF @Sys_WorkstationName = 'Default'	
	BEGIN
		SET @Sys_WorkstationName = (SELECT @@SERVERNAME);
	END
	DECLARE @CurrentDataTime datetime;
	SET @CurrentDataTime = GETDATE();

    INSERT INTO [Sys_RoleMaster]
           (	
				[RoleCode],
				[RoleName],
				[RoleDescription],
				[Sys_DateOfCreation],
				[Sys_DateOfModification],
				[Sys_CreatedByID],
				[Sys_ModifiedByID],
				[Sys_DeleteType],
				[Sys_IsDeleted],
				[Sys_OrganizationID],
				[Sys_InitialPrimaryKeys],
				[Sys_WorkstationName]
			)
     VALUES
           (
				@RoleCode,
				@RoleName,
				@RoleDescription,
				@CurrentDataTime,
				@CurrentDataTime,
				@Sys_CreatedByID,
				@Sys_ModifiedByID,
				@Sys_DeleteType,
				0,
				@Sys_OrganizationID,
				@Sys_InitialPrimaryKeys,
				@Sys_WorkstationName
			);

			SET @RoleKey = SCOPE_IDENTITY();
	        SET @Sys_DateOfCreation = @CurrentDataTime;
END
GO

--Ivy_Sys_RoleMaster_Insert 'SYSSPRADM','System Super Admin', 'Super Administrator for the Portal','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
--Ivy_Sys_RoleMaster_Insert 'SYSADMIN','System Admin', 'Administrator for the Portal','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
--Ivy_Sys_RoleMaster_Insert 'SYSOPRAT','System Operator', 'Operator for the Portal','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
--Ivy_Sys_RoleMaster_Insert 'SCTSUPADM','Society Super Admin', 'Super Administrator for the Society related operations','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
--Ivy_Sys_RoleMaster_Insert 'SCTADMIN','Society Admin', 'Administrator for the Society, a member of Management Committee','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
--Ivy_Sys_RoleMaster_Insert 'SCTOPRAT','Society Operator', 'Operator for the Society, mostly employees of the society','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
--Ivy_Sys_RoleMaster_Insert 'APTBLDR','Apartment Builder', 'Builder of the Apartment complex','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
--Ivy_Sys_RoleMaster_Insert 'FLTOWNER','Flat Owner', 'Flat owner','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
--Ivy_Sys_RoleMaster_Insert 'FLTRESI','Resident', 'Resident of a Flat','SysAdmin','SysAdmin',0,-1,NULL,'Default'
--GO
